<template>
  <div>
    <mainTable :title="'房产详情'" :table="table" :type="'address'" @btn="btn" />
    <el-pagination
      style="text-align:center; margin:20px"
      background
      layout="prev, pager, next"
      :total="totals"
      :page-size="page._limit"
      :current-page.sync="currentPage"
      @current-change="currentChange"
    />
  </div>
</template>

<script>
import { getClassificationList, getClassificationListById } from '@/api/classification'

export default {
  data() {
    return {
      table: [],
      totals: 0,
      currentPage: 0,
      page: {
        _limit: 2,
        _start: 0
      }
    }
  },
  async created() {
    if (this.$route.params.data) {
      console.log('ws', this.$route.params.data)
      this.table = this.$route.params.data
      console.log(1235555555, this.table)
    } else {
      const data = await getClassificationList()
      console.log(123, data.data)
      this.table = data.data
      console.log(99999, this.table)
      this.total()
      this.PageData()
    }
  },
  methods: {
    // 重新获取总数量
    async total() {
      const { data } = await getClassificationList()
      console.log(data)
      this.table = await data
      this.totals = this.table.length
      console.log(this.totals)
    },
    // 刷新回显表格指定数量的数据
    async PageData() {
      const { data } = await getClassificationList(this.page)
      // console.log(data)
      this.table = data
    },
    async currentChange(sum) {
      const num = sum * this.page._limit - 1
      this.page._start = num
      // this.total()
      this.PageData(this.page)
    },
    async btn(id) {
      const data = await getClassificationListById(id)
      console.log(987, data.data)
      // 本地保存
      const res = JSON.stringify(data.data)
      localStorage.setItem('xiangqing', res)
      this.$router.push({
        name: 'details',
        params: {
          data
        }
      })
    }
  }
}
</script>

<style>

</style>
